const {ipcMain, app} = require("electron");


module.exports = class Menu{
    screen;
    constructor(screen) {
        this.screen = screen;
        this.init();
    }
    init(){
        ipcMain.on('exitScreen',(e,args) =>{
            app.quit();
        })
        ipcMain.on('minimizeScreen',(e,args) =>{
            this.screen.minimize();
        })
        ipcMain.on('maximizeScreen',(e,args) =>{
            if(this.screen.isMaximized()){
                this.screen.unmaximize();
            }else
                this.screen.maximize();

            this.sendStatus();
        })
        ipcMain.on('fullScreen',(e,args) =>{
            if(this.screen.isFullScreen()){
                this.screen.setFullScreen(false);
            }else
                this.screen.setFullScreen(true);

            this.sendStatus();
        })
        ipcMain.on('forward',(e,args) =>{
            this.screen.webContents.goForward();
        })
        ipcMain.on('back',(e,args) =>{
            this.screen.webContents.goBack();
        })
        ipcMain.on('fresh',(e,args) =>{
            this.screen.webContents.reload();
        })
    }
    sendStatus(){
        this.screen.webContents.send('screenStatus',{isMaximized:this.screen.isMaximized(),isFullScreen:this.screen.isFullScreen()});
    }
}